package online.shenjian.nacos.consumer;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * @author shenjian
 * @since 2022/12/7
 */
@RestController
public class HelloWorldController {

    private final RestTemplate restTemplate;

    public HelloWorldController(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @GetMapping(value = "/hello")
    public String echo(@RequestParam String name) {
        // 调用注册到nacos的服务，名称即spring.application.name指定的名称
        return restTemplate.getForObject("http://nacos-service-provider/hello?name={name}", String.class, name);
    }
}
